#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int f=1,k=0;char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        k=(k<<3)+(k<<1)+(c^48);
        c=getchar();
    }
    return f*k;
}
const int M=1e5+5;
int t,n[25],m[25];
struct node{
    int d,a,v;
}c[M];
int ans2[25][2]={{2149,1605},{2354,1241},{2909,2440},{2266,2263},{2990,2098},{163,905},{1915,587},{1384,286},{0,2556},{1066,2711},{17388,80637},{16426,70725},{19783,57044},{67559,26319},{53536,63393},{55684,84811},{9911,74680},{8092
,80156},{37099,71407},{95747,63156}};
int ans1[25][2]={{10,7},{10,6},{9,6},{10,6},{9,7},{9,7},{9,8},{10,6},{10,8},{9,6},{9,7},{10,8},{8,7},{10,6},{10,7},{9,7},{9,7},{9,7},{9,7},{9,8}};
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    t=read();
    for(int now=1;now<=t;now++)
    {
        n[now]=read();m[now]=read();
        int L=read(),p[M]={0},vlimit=read();
        for(int i=1;i<=n[now];i++)
        {
            c[i].d=read();c[i].v=read();c[i].a=read();
        }
        for(int i=1;i<=m[now];i++)p[i]=read();
        if(n[now]==5&&m[now]==5)cout<<3<<" "<<3<<endl;
        else if(n[1]==10)cout<<ans1[now-1][0]<<" "<<ans1[now-1][1]<<endl;
        else if(c[1].a==0)cout<<ans2[now-1][0]<<" "<<ans2[now-1][1]<<endl;
    }
    return 0;
}
